package com.neuedu.dao.impl;

import com.neuedu.dao.XiaoQuDao;
import com.neuedu.model.User;
import com.neuedu.model.XiaoQu;
import com.neuedu.utils.DBUtil;

import java.util.List;

public class XiaoQuDaoImpl implements XiaoQuDao {
    @Override
    public List<XiaoQu> selectPageList(Integer limitParams1, Integer limitParams2, String startTime, String endTime, String name) {
        List<XiaoQu> list = DBUtil.findByWhere(XiaoQu.class,
                "chuangjianshijian >= ? and chuangjianshijian <= ? and mingcheng like ? limit ?,?",
                startTime, endTime, "%" + name + "%", limitParams1, limitParams2);
        return list;
    }

    @Override
    public int selectCount(String startTime, String endTime, String name) {
        return DBUtil.findByWhere(XiaoQu.class,
                "chuangjianshijian >= ? and chuangjianshijian <= ? and mingcheng like ?",
                startTime, endTime, "%" + name + "%").size();

    }

    @Override
    public int add(XiaoQu xiaoQu) {
        xiaoQu.setId(null);

        return DBUtil.insert(xiaoQu);
    }

    @Override
    public int del(Integer[] ids) {
        String where="id in (";
        for (int i = 0; i < ids.length; i++) {
            where=where+"?";
            if(i!=ids.length-1){
                where=where+",";
            }else{
                where=where+")";
            }
        }
        return DBUtil.delete(XiaoQu.class,where,ids);
    }

    @Override
    public XiaoQu selectXiaoQuOne(Integer id) {
        return DBUtil.findOneByWhere(XiaoQu.class,"id=?",id);
    }

    @Override
    public int updateXiaoQu(XiaoQu xiaoQu) {
        return DBUtil.updateSelective(xiaoQu,"id=?",xiaoQu.getId());
    }

    @Override
    public List<XiaoQu> selectAll() {
        return DBUtil.findAll(XiaoQu.class);
    }
}
